Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vireo ResizeArray implementation #464

Merged
merged 4 commits into from
Jun 27, 2018
Merged

Conversation

rajsite
Copy link
Member

@rajsite rajsite commented Jun 26, 2018

Changes the existing resizeArray implementation to use the valueRef interface. Also allows getArrayDimensions to work with all valid Array types.

@rajsite rajsite requested review from cglzaguilar and gleono June 26, 2018 22:48
@rajsite rajsite requested review from sanmut and spathiwa as code owners June 26, 2018 22:48
@rajsite rajsite removed request for spathiwa and sanmut June 26, 2018 22:48
Copy link
Contributor

@cglzaguilar cglzaguilar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider addressing minor feedback,

@@ -279,20 +279,29 @@ VIREO_EXPORT Int32 EggShell_GetArrayDimLength(TypeManagerRef tm, const char* viN
}
//------------------------------------------------------------
//! Resizes a variable size Array symbol to have new dimension lengths specified by newLengths, it also initializes cells for non-flat data.
//! Returns -1 if the symbols is not found, -2 if was not possible to resize the array and 0 if resizing was successful.
VIREO_EXPORT Int32 EggShell_ResizeArray(TypeManagerRef tm, const char* viName, const char* eltName, Int32 rank, Int32* newLengths)
VIREO_EXPORT EggShellResult EggShell_ResizeArray(TypeManagerRef tm, const TypeRef actualType, const void* pData,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider const also for TypeManagerRef. Also, add at least null checks for tm. We might need to update other API calls to validate tm.

Copy link
Contributor

@gleono gleono Jun 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the other functions in CEntryPoints.cpp use const for the TypeManagerRef. Maybe we can submit that as a separate change before merging ni:api-type-refactor to master.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made an issue to track things we should verify across all the implemented functions before merging. Tracked as "Consistent marking of parameters as const on the CEntryPoints" in #466

var newDimensionsLength = newDimensions.length;
var dimensionsPointer = Module.stackAlloc(newDimensionsLength * LENGTH_SIZE);
var i, currentDimension;
for (i = 0; i < newDimensionsLength; i += 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it common practice is JS to use i += 1, instead of i++?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a linting rule in .eslintrc.js. Why is preferred? Because ++ are subject to auto-semicolon insertion. Checkout eslint docs. If we really don't like it, there's also the exception "allowForLoopAfterthoughts": true

Copy link
Contributor

@gleono gleono left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I guess only find out if there's a possible memory leak or not.

' (typeRef: ' + valueRef.typeRef + ')' +
' (dataRef: ' + valueRef.dataRef + ')');
}
Module.stackRestore(stack);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if any of the Errors thrown above would cause a memory leak?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Written under the assumption that on exception throw to JS the whole Vireo instance (stack + heap) should be considered corrupt.

We should verify that assumption is usable and standardize across functions prior to merge. Tracked as "Robustness of stackSave / restore and error recovery the api should enable" in #466

var newDimensionsLength = newDimensions.length;
var dimensionsPointer = Module.stackAlloc(newDimensionsLength * LENGTH_SIZE);
var i, currentDimension;
for (i = 0; i < newDimensionsLength; i += 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a linting rule in .eslintrc.js. Why is preferred? Because ++ are subject to auto-semicolon insertion. Checkout eslint docs. If we really don't like it, there's also the exception "allowForLoopAfterthoughts": true

@@ -279,20 +279,29 @@ VIREO_EXPORT Int32 EggShell_GetArrayDimLength(TypeManagerRef tm, const char* viN
}
//------------------------------------------------------------
//! Resizes a variable size Array symbol to have new dimension lengths specified by newLengths, it also initializes cells for non-flat data.
//! Returns -1 if the symbols is not found, -2 if was not possible to resize the array and 0 if resizing was successful.
VIREO_EXPORT Int32 EggShell_ResizeArray(TypeManagerRef tm, const char* viName, const char* eltName, Int32 rank, Int32* newLengths)
VIREO_EXPORT EggShellResult EggShell_ResizeArray(TypeManagerRef tm, const TypeRef actualType, const void* pData,
Copy link
Contributor

@gleono gleono Jun 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the other functions in CEntryPoints.cpp use const for the TypeManagerRef. Maybe we can submit that as a separate change before merging ni:api-type-refactor to master.

@rajsite rajsite merged commit 42e48c7 into ni:api-type-refactor Jun 27, 2018
@rajsite rajsite deleted the resize-array branch June 27, 2018 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants